import "../../../scss/special/pay.scss"
import $ from "jquery"
import com from "../../utils/common"
import "../../utils/oldcommon/layer"
import wxtool from "../components/weixin";
import wxpay from "../components/wxpay";

let user = wxtool.getWxUserinfo();
console.log(user)
$(function () {
  let page = {
    _init: function () {
      let self = this;
      // 获取用户账号剩余试用期
      com.ajax({
        url: "/user/expireTime",
        ok: function (data) {
          console.log(data);
          let expireHours = data["msg"];
          let expireDays = Math.ceil(expireHours / 24);
          $("#overDay").html(expireDays);
          self._pageFunc();
        }
      });
    },
    _pageFunc: function () {
      let self = this;
      $("body").on("click", '.recharge', function () {
        com.alertDialog('客牛营销系统为虚拟类服务产品，付费即使用，费用不可退还，账号不可转让。');
      });

      $("body").on("click", ".selectType", function () {
        let $this = this;
        $($this).addClass("nian").siblings().removeClass("nian");
        let amount = parseInt($(this).find("span").text()) * 100;
        self._payStatus.amount = amount;
        self._payStatus.days = $(this).data("days");
      })

      $("#pay").click(function () {
        self._payStatus.startpay();//分为单位
      })
    },
    _payStatus: {
      amount: 149900,//默认年费
      days: 365,
      startpay: function () {
        let self = this;
        console.log(self)
        com.ajax({
          url: "/wx/createOrder",
          data: {
            fee: 1,
            reqUrl: window.location.href,
            openid: user.openid,
            chargeid: self.days,
          },
          ok: function (data) {
            wxpay(data)
          }
        });
      },

      pay_ok: function () {
        layer.open({
          content: '恭喜您完成支付，请进入会员中心即可发布您的活动.'
          , btn: ['马上去看一下'],
          shadeClose: false
          , yes: function (index) {
            window.location.href = '../user_page/user_center.html';
          }
        });
      },
      pay_fail: function (state) {
        if (state == 'cancel') {
          com.alertDialog('您已经取消了支付.');
        } else {
          com.alertDialog('支付没有完成.');
        }
      },
      gopay: function () {
        page._payStatus.startpay();//分为单位
      },
    }
  }
  page._init();
})
















